/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kallsonys.object;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author alladiab
 */
@Entity
@Cacheable(false)
@Table(name = "ADDRESS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Address.findAll", query = "SELECT a FROM Address a"),
    @NamedQuery(name = "Address.findByAddressid", query = "SELECT a FROM Address a WHERE a.addressid = :addressid"),
    @NamedQuery(name = "Address.findByAddressstreet", query = "SELECT a FROM Address a WHERE a.addressstreet = :addressstreet"),
    @NamedQuery(name = "Address.findByAddresstype", query = "SELECT a FROM Address a WHERE a.addresstype = :addresstype"),
    @NamedQuery(name = "Address.findByAddresstown", query = "SELECT a FROM Address a WHERE a.addresstown = :addresstown"),
    @NamedQuery(name = "Address.findByAddressphonenumber", query = "SELECT a FROM Address a WHERE a.addressphonenumber = :addressphonenumber"),
    @NamedQuery(name = "Address.findByCustumerId", query = "SELECT a FROM Address a WHERE a.customerid = :customerid")})
public class Address implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @GeneratedValue(generator="AddressSeq")
    @SequenceGenerator(name="AddressSeq",sequenceName="SEQ_ADDRESS",initialValue=1, allocationSize=1)
    @Column(name = "ADDRESSID")
    private Long addressid;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "ADDRESSSTREET")
    private String addressstreet;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ADDRESSTYPE")
    private BigInteger addresstype;
    @Size(max = 50)
    @Column(name = "ADDRESSTOWN")
    private String addresstown;
    @Size(max = 15)
    @Column(name = "ADDRESSPHONENUMBER")
    private String addressphonenumber;
    @OneToMany(mappedBy = "lastusedaddressid")
    private List<Customer> customerList;
    
    @JoinColumn(name = "CUSTOMERID", referencedColumnName = "CUSTOMERID")
    @ManyToOne(fetch= FetchType.LAZY, optional = false)
    private Customer customerid;
    @JoinColumn(name = "CITYID", referencedColumnName = "CITYID")
    @ManyToOne(optional = false)
    private City cityid;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "addressid")
    private List<OrderOms> orderOmsList;

    public Address() {
    }

    public Address(Long addressid) {
        this.addressid = addressid;
    }

    public Address(Long addressid, String addressstreet, BigInteger addresstype) {
        this.addressid = addressid;
        this.addressstreet = addressstreet;
        this.addresstype = addresstype;
    }

    public Long getAddressid() {
        return addressid;
    }

    public void setAddressid(Long addressid) {
        this.addressid = addressid;
    }

    public String getAddressstreet() {
        return addressstreet;
    }

    public void setAddressstreet(String addressstreet) {
        this.addressstreet = addressstreet;
    }

    public BigInteger getAddresstype() {
        return addresstype;
    }

    public void setAddresstype(BigInteger addresstype) {
        this.addresstype = addresstype;
    }

    public String getAddresstown() {
        return addresstown;
    }

    public void setAddresstown(String addresstown) {
        this.addresstown = addresstown;
    }

    public String getAddressphonenumber() {
        return addressphonenumber;
    }

    public void setAddressphonenumber(String addressphonenumber) {
        this.addressphonenumber = addressphonenumber;
    }

    @XmlTransient
    public List<Customer> getCustomerList() {
        return customerList;
    }

    public void setCustomerList(List<Customer> customerList) {
        this.customerList = customerList;
    }

    public Customer getCustomerid() {
        return customerid;
    }

    public void setCustomerid(Customer customerid) {
        this.customerid = customerid;
    }

    public City getCityid() {
        return cityid;
    }

    public void setCityid(City cityid) {
        this.cityid = cityid;
    }

    @XmlTransient
    public List<OrderOms> getOrderOmsList() {
        return orderOmsList;
    }

    public void setOrderOmsList(List<OrderOms> orderOmsList) {
        this.orderOmsList = orderOmsList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (addressid != null ? addressid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Address)) {
            return false;
        }
        Address other = (Address) object;
        if ((this.addressid == null && other.addressid != null) || (this.addressid != null && !this.addressid.equals(other.addressid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return addressstreet + "-" + addressphonenumber;
    }
    
}
